#include "doctordetailwidget.h"
#include "ui_doctordetailwidget.h"
#include <QMessageBox>

DoctorDetailWidget::DoctorDetailWidget(const Doctor& doctor, QWidget *parent) :
    QWidget(parent),
    ui(new Ui::DoctorDetailWidget),
    m_doctor(doctor)
{
    ui->setupUi(this);
    displayDoctorInfo();
}

DoctorDetailWidget::~DoctorDetailWidget()
{
    delete ui;
}

void DoctorDetailWidget::displayDoctorInfo()
{
    // 显示医生详细信息
    ui->nameLabel->setText(m_doctor.realName);
    ui->titleLabel->setText(m_doctor.title);
    ui->departmentLabel->setText(m_doctor.departmentName);
    ui->specialtyLabel->setText(m_doctor.specialty);
    ui->educationLabel->setText(m_doctor.education);
    ui->experienceLabel->setText(QString::number(m_doctor.experience) + " 年");
    ui->introductionText->setPlainText(m_doctor.introduction);
    ui->workTimeLabel->setText(m_doctor.workTime);
    ui->feeLabel->setText(QString("¥ %1").arg(m_doctor.consultationFee, 0, 'f', 2));
    ui->limitLabel->setText(QString::number(m_doctor.dailyPatientLimit) + " 人");
    ui->bookedLabel->setText(QString::number(m_doctor.bookedCount) + " 人");
    ui->remainingLabel->setText(QString::number(m_doctor.remainingSlots) + " 人");
    
    // 如果剩余预约数为0，禁用预约按钮
    if (m_doctor.remainingSlots <= 0) {
        ui->bookButton->setEnabled(false);
        ui->bookButton->setText("已约满");
    }
}

void DoctorDetailWidget::on_closeButton_clicked()
{
    emit closed();
    this->close();
}

void DoctorDetailWidget::on_bookButton_clicked()
{
    // 关闭详情页，由父组件处理预约逻辑
    emit closed();
    this->close();
}

